import Vue from 'vue'
import VueRouter from 'vue-router'
import login from '../components/other/login.vue'
import home from '../components/mainPage/home.vue'
import homepage from '../components/mainPage/homePage.vue'
import breedingRecord from '../components/breedingInformation/breedingRecord.vue'
import userPage from '../components/mainPage/userPage.vue'
import userDetails from '../components/mainPage/userDetails.vue'
import finenessDete from '../components/cashmereInfo/finenessDete.vue'
import pedigreeFile from '../components/sheepFlockInfo/pedigreeFile.vue'
import lambingRecord from '../components/breedingInformation/lambingRecord.vue'
// import dataAnalysis from '../components/statistics/dataAnalysis.vue'
import basicInfo from '../components/sheepFlockInfo/basicInfo.vue'
import cardInfo from '../components/sheepFlockInfo/cardInfo.vue'
import productionPerformance from '../components/sheepFlockInfo/productionPerformance.vue'
import dataAnalysis from '../components/cashmereInfo/dataAnalysis.vue'
import breedInfo from '../components/breedInfo/breedRecord.vue'
import lambingInfo from '../components/breedInfo/lambingInfo.vue'
import casesRecord from '../components/casesInfo/casesRecord.vue'
import salesRecord from '../components/salesInfo/salesRecord.vue'

Vue.use(VueRouter)
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

//导入Nprogress
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'


const routes = [

]

const router = new VueRouter({
  routes: [
    { path: '/login', component: login },
    { path: '/', redirect: '/login' },
    {
      path: '/home',
      component: home,
      redirect: '/homePage',
      children: [
        { path: '/homePage', component: homepage },
        { path: '/breedingRecord', component: breedingRecord },
        { path: '/userPage', component: userPage },
        { path: '/userDetails', component: userDetails },
        { path: '/finenessDete', component: finenessDete },
        { path: '/pedigreeFile', component: pedigreeFile },
        { path: '/lambingRecord', component: lambingRecord },
        { path: '/dataAnalysis', component: dataAnalysis },
        { path: '/basicInfo', component: basicInfo },
        { path: '/cardInfo', component: cardInfo },
        { path: '/productionPerformance', component: productionPerformance },
        { path: '/dataAnalysis', component: dataAnalysis },
        { path: '/breedInfo', component: breedInfo },
        { path: '/lambingInfo', component: lambingInfo },
        { path: '/casesRecord', component: casesRecord },
        { path: '/salesRecord', component: salesRecord },
      ]
    }
  ]
})

router.beforeEach((to, from, next) => {
  NProgress.start()
  next()
})
router.afterEach(() => {
  NProgress.done()
})

// 挂载路由导航守卫
/* router.beforeEach((to, from, next) => {
  if (to.path === '/login') return next();
  const tokenStr = window.sessionStorage.getItem('token')
  if (!tokenStr) return next('/login')
  next();
}) */

export default router